package com.tiles.tools;

import java.security.MessageDigest;

public class Md5Util {

    public static String md5Password(String password) throws Exception{
        try{
            MessageDigest digest = MessageDigest.getInstance("md5");
            byte[] result = digest.digest(password.getBytes());
            StringBuffer stringBuffer = new StringBuffer();


            for (byte b:result){
                int num = b&0xf1;
                String str = Integer.toHexString(num);
                if (str.length()==1){
                    stringBuffer.append("0");
                }
                stringBuffer.append(str);
            }
            return stringBuffer.toString();
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }

    }
}
